home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
CWL2A_1.ARJ
/
UPDATE.DOC
< prev
next >
Wrap
Text File
|
1991-11-16
|
22KB
|
705 lines
Here are the last minute changes to The C Window Library manual:
Popup Menu Macros
-----------------
The following macros have been added to The C Window Library Version 2.0:
POPUP_SCROLL_UP_CHAR(p) - This is the scroll up character that is displayed
if the POPUPMOUSESCROLL option is on for the
popup menu p. The default character is the up
arrow.
POPUP_SCROLL_DOWN_CHAR(p) - This is the scroll down character that is
displayed if the POPUPMOUSESCROLL option is on
for the popup menu p. The default character is
the down arrow.
POPUP_SCROLL_UP_ATTR(p) - This is the color attribute for the scroll up
character that is displayed if the
POPUPMOUSESCROLL option is on for the popup menu
p. The default character is the attribute of the
popup window.
POPUP_SCROLL_DOWN_ATTR(p) - This is the color attribute for the scroll
down character that is displayed if the
POPUPMOUSESCROLL option is on for the popup
menu p. The default character is the attribute
of the popup window.
POPUP_SCROLL_UP_ROW(p) - This is the row that the scroll up character is
displayed in the popup window. The default is the
bottom border of the window
POPUP_SCROLL_UP_COLUMN(p) - This is the column that the scroll up character
is displayed in the popup window. The default
is column 1.
POPUP_SCROLL_DOWN_ROW(p) - This is the row that the scroll down character is
displayed in the popup window. The default is the
bottom border of the window
POPUP_SCROLL_DOWN_COLUMN(p) - This is the column that the scroll down
character is displayed in the popup window.
The default is column 1.
Popup Menu's pre-function for mouse
-----------------------------------
When the POPUPMOUSESCROLL option is used for popup menus, the menu can be
scrolled automatically by placing the mouse on either the up or down scroll
characters on the popup window, and pressing the left mouse button.
The normal pre-function for the popup menu, namely the function pointed to
by global_popup_prefunc, is disabled if you use the mouse to scroll through
the entries in the manner described above. If you want to perform a
function when the menu bar is moved automatically from choice to choice, you
should use the popup_mouse_move_func function pointer. Here is the
prototype:
void (*popup_mouse_move_func)(POPUP_MENU_PTR p, unsigned current)
p is the current popup menu, and current is the current selection that the
highlight bar is on.
Note the difference in the second argument. The global_popup_prefunc
function pointer has a pointer to an integer as the second argument, while
the popup_mouse_move_func has an integer as the second argument. Also
note that the popup_mouse_move_func returns nothing, while the
global_popup_prefunc returns a value back to the menu manager.
If you use the mouse the 'normal' way (pointing the mouse to the actual menu
entry and moving the mouse up or down while holding the left mouse button
down), the normal pre-function is not disabled.
The reason for having the popup_mouse_move_func function pointer is that
there may be a description displayed for each menu entry, where the
displaying of the menu entry is done by the function pointed to by
global_popup_prefunc. Here is a small example:
#include "menu.h"
#include "cwlmouse.h"
int display_choice();
void do_display_choice();
POPUP_MENU_PTR p;
/* other initializations */
main()
{
WindowInitializeSystem();
WindowSaveInitial();
MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,1,1);
p = PopupCreateMenu(/* arguments */);
PopupSetOptions(p,POPUPMOUSE|POPUPMOUSESCROLL,1);
global_popup_prefunc = display_choice;
popup_move_mouse_func = do_display_choice;
/*
...
*/
}
display_choice(POPUP_MENU_PTR p, int *choice)
{
/* display info for entry in a window */
return POPUP_CONTINUE;
}
void do_display_choice(POPUP_MENU_PTR p, int choice)
{
display_choice(p,&choice);
}
Creating menus dynamically
--------------------------
You can now create bar and popup menus dynamically, instead of using the
static method explained in the manual.
Creating popup menu entries dynamically
---------------------------------------
Here is an example:
Usual method:
------------
POPUP_MENU_ENTRY menu_items[] = {
" Load F3", /* entry name */
1, /* row number */
'L', /* hotkey */
F3, /* secondary hotkey */
menu_func, /* function to call if
chosen */
" Pick Alt-F3",2, 'P',ALTF3,menu_func,
" New" ,3, 'N',0,menu_func,
" Save F2",4, 'S',F2,menu_func,
" Write to ",5, 'W',0,menu_func,
" Directory ",6, 'D',0,menu_func,
" Change Dir" ,7, 'C',0,menu_func,
" OS shell" ,8, 'O',0,menu_func,
" Quit Alt-X" ,9,'Q',ALTX,menu_func,
/* Terminate with a CWL_NULL and 0 */
CWL_NULL,0};
New Method
----------
#include "menu.h"
#define NUMENTRIES 9
POPUP_MENU_ENTRY_PTR menu_array; /* Notice that we have a pointer to what
will be an array of POPUP_MENU_ENTRY's
*/
POPUP_MENU_PTR p;
main()
{
WindowInitializeSystem();
/* Initialize with at least number of total entries */
menu_array = PopupAllocate(NUMENTRIES);
/* Call function to create entries in menu_array sequentially */
PopupCreateEntry(menu_array, /* POPUP_MENU_ENTRY pointer */
1, /* entry number */
/* The rest of the arguments are just like the old method */
" Load F3", /* menu string */
1, /* row number */
'L', /* hotkey letter */
F3, /* secondary hotkey */
menu_func); /* function to perform */
/* do rest of the entries */
PopupCreateEntry(menu_array,2," Pick Alt-F3",2,'P',ALTF3,menu_func);
PopupCreateEntry(menu_array,3," New",3,'N',0,menu_func);
PopupCreateEntry(menu_array,4," Save F2",4,'S',F2,menu_func);
PopupCreateEntry(menu_array,5," Write to ",5,'W',0,menu_func);
PopupCreateEntry(menu_array,6," Directory ",6,'D',0,menu_func);
PopupCreateEntry(menu_array,7," Change Dir ",7,'C',0,menu_func);
PopupCreateEntry(menu_array,8," OS Shell ",8,'O',0,menu_func);
PopupCreateEntry(menu_array,9," Quit Alt-X ",9,'Q',ALTX,0,menu_func);
/* end all of the menu entries */
PopupEntryEnd(menu_array,NUMENTRIES);
/* create menu */
p = PopupCreateMenu(menu_array, /* rest of the arguments */);
/* ... */
/* Dispose of menu entries created */
PopupDeallocate(menu_array);
}
The difference between the above method and the method used to globally
initialize an array are the following:
1) The variable type for menu_array is POPUP_MENU_ENTRY_PTR, not
POPUP_MENU_ENTRY as the normal method would have done.
2) You must call the PopupAllocate() function to allocate space for the
number of entries desired. If you do not call PopupAllocate(), you will
surely get a memory overwrite error. The return value to PopupAllocate()
must be assigned to a POPUP_MENU_ENTRY_PTR, as the above example shows.
The array of menu entries are allocated from the heap at runtime, as
opposed to the static method which sets up the memory scheme at link time.
3) The next thing you must do is to fill in the entry information by calling
the PopupCreateEntry() function. The first argument to the
PopupCreateEntry() function is the POPUP_MENU_ENTRY_PTR. The second
argument is the entry
number to assign this information to. The rest of the arguments are the
same order as the usual method i.e. menu string, row, hotkey, etc.
PopupCreateEntry() is called for each field desired.
4) The PopupEndEntry() function must be called to terminate the list of
entries. The first argument is the POPUP_MENU_ENTRY_PTR, and the second
argument is the total number of entries defined.
5) You should call PopupDeallocate() to free the memory assigned to the array
of menu_entries. The only argument to PopupDeallocate() is the
POPUP_MENU_ENTRY_PTR. Only call PopupDeallocate() after you have called
PopupMenuFree() or any function that disposes of the POPUP_MENU_PTR.
All of these functions except for PopupAllocate() have no return values.
The PopupAllocate() function returns a POPUP_MENU_ENTRY_PTR if successful,
and a null pointer if unsuccessful.
The advantages of using the above method over the first method is that
POPUP_MENU_ENTRY's are dynamically allocated rather than statically declared
at compile time. This allows the programmer to create loops to set up
the entries, read entry information from a file and assign this info to a
POPUP_MENU_ENTRY, etc.
You could also do the following:
#include "menu.h"
#define NUMENTRIES 9
POPUP_MENU_ENTRY menu_array[NUMENTRIES+1]; /* We must have at least 1 more
than the number of entries */
POPUP_MENU_PTR p;
main()
{
/* ... */
/* Call function to create entries in menu_array sequentially */
PopupCreateEntry(menu_array, /* POPUP_MENU_ENTRY pointer */
1, /* entry number */
/* The rest of the arguments are just like the old method */
" Load F3", /* menu string */
1, /* row number */
'L', /* hotkey letter */
F3, /* secondary hotkey */
menu_func); /* function to perform */
/* do rest of the entries */
PopupCreateEntry(menu_array,2," Pick Alt-F3",2,'P',ALTF3,menu_func);
PopupCreateEntry(menu_array,3," New",3,'N',0,menu_func);
PopupCreateEntry(menu_array,4," Save F2",4,'S',F2,menu_func);
PopupCreateEntry(menu_array,5," Write to ",5,'W',0,menu_func);
PopupCreateEntry(menu_array,6," Directory ",6,'D',0,menu_func);
PopupCreateEntry(menu_array,7," Change Dir ",7,'C',0,menu_func);
PopupCreateEntry(menu_array,8," OS Shell ",8,'O',0,menu_func);
PopupCreateEntry(menu_array,9," Quit Alt-X ",9,'Q',ALTX,0,menu_func);
/* end all of the menu entries */
PopupEntryEnd(menu_array,NUMENTRIES);
}
The method above does not call PopupAllocate() because the number of
entries was already determined and an array was already set up at compile
time.
PopupCreateEntry() is called for each menu entry as before, and
PopupEntryEnd() is called to terminate the menu entries.
To use this method, you must declare an array of menu entries with at least
one more than the desired number of entries. Also note that
PopupDeallocate() MUST NOT be called because the array of menu entries was
not created with PopupAllocate().
Creating bar menu entries dynamically
-------------------------------------
Here is an example:
Usual method:
------------
#include "menu.h"
int menu_func();
BAR_MENU_ENTRY bar_items[] = {
"File",1,4,'F',ALTF,menu_func,
"Edit",1,10,'E',0,menu_func,
"Run",1,17,'R',0,menu_func,
"Compile",1,23,'C',0,menu_func,
"Project",1,33,'P',0,menu_func,
"Options", 1,43,'O',0,menu_func,
"Debug",1,53,'D',0,menu_func,
"Break/watch",1,61,'B',0,menu_func,
CWL_NULL};
New Method
----------
#include "menu.h"
#define NUMENTRIES 8
BAR_MENU_ENTRY_PTR menu_array; /* Notice that we have a pointer to what
will be an array of BAR_MENU_ENTRY's
*/
BAR_MENU_PTR b;
main()
{
WindowInitializeSystem();
/* Initialize with at least number of total entries */
menu_array = BarAllocate(NUMENTRIES);
/* Call function to create entries in menu_array sequentially */
BarCreateEntry(menu_array, /* BAR_MENU_ENTRY pointer */
1, /* entry number */
/* The rest of the arguments are just like the old method */
"File", /* menu string */
1, /* row number */
4, /* col. number */
'F', /* hotkey letter */
ALTF, /* secondary hotkey */
menu_func); /* function to perform */
/* do rest of the entries */
BarCreateEntry(menu_array,2,"Edit",1,10,'E',0,menu_func);
BarCreateEntry(menu_array,3,"Run",1,17,'R',0,menu_func);
BarCreateEntry(menu_array,4,"Compfile",1,23,'C',0,menu_func);
BarCreateEntry(menu_array,5,"Project",1,33,'P',0,menu_func);
BarCreateEntry(menu_array,6,"Options",1,43,'O',0,menu_func);
BarCreateEntry(menu_array,7,"Debug", 1,53,'D',0,menu_func);
BarCreateEntry(menu_array,8,"Break/watch",1,61,'B',0,menu_func);
/* end all of the menu entries */
BarEntryEnd(menu_array,NUMENTRIES);
/* create menu */
b = BarCreateMenu(menu_array, /* rest of the arguments */);
/* ... */
/* Dispose of menu entries created */
BarDeallocate(menu_array);
}
The difference between the above method and the method used to globally
initialize an array are the following:
1) The variable type for menu_array is BAR_MENU_ENTRY_PTR, not
BAR_MENU_ENTRY as the normal method would have done.
2) You must call the BarAllocate() function to allocate space for the
number of entries desired. If you do not call BarAllocate(), you will
surely get a memory overwrite error. The return value to BarAllocate()
must be assigned to a BAR_MENU_ENTRY_PTR, as the above example shows.
The array of menu entries are allocated from the heap at runtime, as
opposed to the static method which sets up the memory scheme at link time.
3) The next thing you must do is to fill in the entry information by calling
the BarCreateEntry() function. The first argument to the BarCreateEntry()
function is the BAR_MENU_ENTRY_PTR. The second argument is the entry
number to assign this information to. The rest of the arguments are the
same order as the usual method i.e. menu string, row, column, hotkey,
etc. BarCreateEntry() is called for each field desired.
4) The BarEndEntry() function must be called to terminate the list of
entries. The first argument is the BAR_MENU_ENTRY_PTR, and the second
argument is the total number of entries defined.
5) You should call BarDeallocate() to free the memory assigned to the array
of menu_entries. The only argument to BarDeallocate() is the
BAR_MENU_ENTRY_PTR. Only call BarDeallocate() after you have called
BarMenuFree() or any function that disposes of the BAR_MENU_PTR.
All of these functions except for BarAllocate() have no return values.
The BarAllocate() function returns a BAR_MENU_ENTRY_PTR if successful,
and a null pointer if unsuccessful.
You could also do the following:
#include "menu.h"
#define NUMENTRIES 8
BAR_MENU_ENTRY menu_array[NUMENTRIES+1]; /* We must have at least 1 more
than the number of entries */
BAR_MENU_PTR b;
main()
{
/* ... */
/* Call function to create entries in menu_array sequentially */
BarCreateEntry(menu_array, /* BAR_MENU_ENTRY pointer */
1, /* entry number */
/* The rest of the arguments are just like the old method */
"File", /* menu string */
1, /* row number */
4, /* col. number */
'F', /* hotkey letter */
ALTF, /* secondary hotkey */
menu_func); /* function to perform */
/* do rest of the entries */
BarCreateEntry(menu_array,2,"Edit",1,10,'E',0,menu_func);
BarCreateEntry(menu_array,3,"Run",1,17,'R',0,menu_func);
BarCreateEntry(menu_array,4,"Compfile",1,23,'C',0,menu_func);
BarCreateEntry(menu_array,5,"Project",1,33,'P',0,menu_func);
BarCreateEntry(menu_array,6,"Options",1,43,'O',0,menu_func);
BarCreateEntry(menu_array,7,"Debug", 1,53,'D',0,menu_func);
BarCreateEntry(menu_array,8,"Break/watch",1,61,'B',0,menu_func);
/* end all of the menu entries */
BarEntryEnd(menu_array,NUMENTRIES);
}
The method above does not call BarAllocate() because the number of
entries was already determined and an array was already set up at compile
time.
BarCreateEntry() is called for each menu entry as before, and BarEntryEnd()
is called to terminate the menu entries.
To use this method, you must declare an array of menu entries with at least
one more than the desired number of entries. Also note that
BarDeallocate() MUST NOT be called because the array of menu entries was
not created with BarAllocate().
Checking for mouse presses
--------------------------
The GET_MPRESS_KEY() and GET_MPRESS_ENHANCED_KEY() macros work the same as
the GET_KEY() and GET_ENHANCED_KEY() macros respectively, except that
GET_MPRESS_KEY() and GET_MPRESS_ENHANCED_KEY() also test to see if one or
more mouse buttons has been pressed.
When GET_MPRESS_KEY() or GET_MPRESS_ENHANCED_KEY() is called, the program is
suspended until a key on the keyboard is pressed, or one or more mouse
buttons has been pressed. The difference between these two macros is that
GET_MPRESS_ENHANCED_KEY() recognizes keys on an enhanced (101 key) keyboard.
Here is a prototype for both of these macros:
unsigned int GET_MPRESS_KEY(int *which)
unsigned int GET_MPRESS_ENHANCED_KEY(int *which)
The only argument is a pointer to an integer which will contain either
MOUSEPRESSED if the mouse was pressed, or KEYBOARDPRESSED if a key on the
keyboard was pressed. The kyboard_idle_func and keyboard_intercept_func
function pointers are fully implemented when either of these macros are
called.
Both of these macros return either the key that was struck, or the mouse
button(s) that was(were) pressed. The values for these mouse buttons are as
follows:
MOUSELEFT_PRESS - Left button was pressed.
MOUSERIGHT_PRESS - Right button was pressed.
MOUSEMIDDLE_PRESS - Middle button was pressed.
MOUSELEFTRIGHT_PRESS - Left and Right was pressed simultaneously.
MOUSEMIDDLERIGHT_PRESS - Middle and Right buttons were pressed
simultaneously.
MOUSEMIDDLELEFT_PRESS - Middle and Left buttons pressed simultaneously.
MOUSEMIDDLERIGHTLEFT_PRESS - Middle, right, and left buttons pressed
simultaneously.
If a keyboard key is hit, the return values are the same as for GET_KEY() or
GET_ENHANCED_KEY().
Example:
#include "cwlmouse.h"
#include "window.h"
#define NORM CREATE_VIDEO_ATTRIBUTE(BLACK_,WHITE_)
void print_nums();
main()
{
int w,b;
unsigned ch;
WindowInitializeSystem();
ClearScreen(NORM);
MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,10,10);
key_idle_func = print_nums;
ch = GET_MPRESS_KEY(&w);
VideoPrintf("\nThe %s was pressed. Value is %d",
(w==MOUSEPRESSED?"Mouse":"Keyboard"),ch);
MouseRestoreSystem();
}
void print_nums()
{
static int count = 0;
MoveCursor(1,1,0);
VideoPrintf("%d",count++);
}